package com.jj.service.impl;

import com.jj.entity.Allocation;
import com.jj.mapper.AllocationMapper;
import com.jj.service.AllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class AllocationServiceImpl implements AllocationService {
    @Autowired
    private AllocationMapper allocationMapper;
    @Override
    @Transactional
    public boolean addAllocation(Allocation allocation) {
        return allocationMapper.addAllocation(allocation)>0?true:false;
    }

    @Override
    @Transactional
    public boolean updateAllocation(Allocation allocation) {
        return allocationMapper.updateAllocation(allocation)>0?true:false;
    }

    @Override
    @Transactional
    public boolean deleteAllocation(Long id) {
        return allocationMapper.deleteAllocation(id)>0?true:false;
    }

    @Override
    public List<Allocation> selectCurrentAllocations(Long studentId) {
        return allocationMapper.selectCurrentAllocations(studentId);
    }

    @Override
    public List<Allocation> selectAllocationHistoryByStudentId(Long studentId) {
        return allocationMapper.selectAllocationHistoryByStudentId(studentId);
    }

    @Override
    public List<Allocation> selectAllocationHistoryByDormitoryId(Long dormitoryId) {
        return allocationMapper.selectAllocationHistoryByDormitoryId(dormitoryId);
    }

    @Override
    public List<Allocation> selectCurrentAllocationByStudentId(Long studentId) {
        return allocationMapper.selectCurrentAllocationByStudentId(studentId);
    }
}
